package com.service.impl;

import com.entry.JiBie;
import com.entry.JiBieA;
import com.entry.JiBieB;
import com.mapper.JiBieMapper;
import com.service.JiBieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@Service
public class JiBieServiceImpl implements JiBieService {

    @Autowired
    private JiBieMapper jiBieMapper;
    @Override
    public JiBie getJiBie() {
       List<JiBieA> listA= jiBieMapper.getJiBieA();
       List<JiBieB> listB=jiBieMapper.getJiBieB();
       JiBie jiBie=new JiBie();
        List yi=new ArrayList();
        List er=new ArrayList();
        List san=new ArrayList();
        List si=new ArrayList();
        for (JiBieA jiBieA : listA) {
            if(jiBieA.getJieBie()!=null) {
                if(jiBieA.getJieBie()==1) yi.add(jiBieA.getType());
                if(jiBieA.getJieBie()==2) er.add(jiBieA.getType());
                if(jiBieA.getJieBie()==3) san.add(jiBieA.getType());
                if(jiBieA.getJieBie()==4) si.add(jiBieA.getType());
            }
        }

        if(yi.size()>0){
            Integer sum=0;
            for (int i = 0; i < yi.size(); i++) {
               sum+=getSum(yi.get(i).toString(),listB);
            }
            jiBie.setYi(sum);
        }else {
            jiBie.setYi(0);
        }
        if(er.size()>0){
            Integer sum=0;
            for (int i = 0; i < er.size(); i++) {
                sum+=getSum(er.get(i).toString(),listB);
            }
            jiBie.setEr(sum);
        }else {
            jiBie.setEr(0);
        }
        if(san.size()>0){
            Integer sum=0;
            for (int i = 0; i < san.size(); i++) {
                sum+=getSum(san.get(i).toString(),listB);
            }
            jiBie.setSan(sum);
        }else {
            jiBie.setSan(0);
        }
        if(si.size()>0){
            Integer sum=0;
            for (int i = 0; i < si.size(); i++) {
                sum+=getSum(si.get(i).toString(),listB);
            }
            jiBie.setSi(sum);
        }else{
            jiBie.setSi(0);
        }
        System.out.println(jiBie);
        return jiBie;

    }

    Integer getSum(String type,List<JiBieB> list){
        Integer sum=0;
        for (JiBieB jiBieB : list) {
            if(jiBieB.getType().toString().equals(type)){
                sum=jiBieB.getSum();
            }
        }
        return sum;
    }
}
